% fname: routing_oddeven__sel_nop__topology_8x8__.m
% ./noxim -routing oddeven -sel nop -dimx 8 -dimy 8  -sim 10000 -warmup 2000 -size 8 8 -buffer 2 -hs 27 0.2 -hs 28 0.2 -hs 35 0.2 -hs 36 0.2 

function [max_pir, max_throughput, min_delay] = routing_oddeven__sel_nop__topology_8x8__(symbol)

data = [
%             pir      avg_delay     throughput      max_delay       rpackets         rflits
           0.0018        16.9662      0.0143145             94            887           7100
           0.0018        15.3937      0.0153387             74            950           7608
           0.0018        16.6992      0.0150723            120            964           7717
           0.0018        15.5895      0.0149729             76            899           7187
           0.0018        16.4184      0.0148458            108            889           7126
           0.0018        14.6179      0.0147021            113            882           7057
           0.0018        16.7476      0.0153437            126            919           7365
           0.0018        16.7276      0.0154335            104            958           7655
           0.0018        16.1101      0.0146371             85            908           7260
           0.0018        15.5934       0.015153             95            878           7031
           0.0018        15.7387      0.0154938             80            930           7437
           0.0018        16.4731      0.0150635             89            949           7592
           0.0018        17.7089      0.0152897            103            962           7706
           0.0018        16.5115      0.0155297             79            917           7330
           0.0018        17.3306      0.0161375            129            968           7746
           0.0018        17.6769      0.0154242            172            941           7527
           0.0018        16.0725      0.0142361             88            897           7175
           0.0018        15.6543      0.0148347             71            920           7358
           0.0018        17.1234      0.0164833            104            989           7912
           0.0018        17.4551       0.014697            109            868           6937
            0.002        17.5054      0.0164032            116           1017           8136
            0.002        17.4688      0.0173206            120           1075           8591
            0.002        19.4348      0.0165685            145           1028           8218
            0.002        16.7108       0.017131            106           1079           8634
            0.002         16.975      0.0162617             79           1041           8326
            0.002        18.0685      0.0157559            186           1008           8067
            0.002        17.0058      0.0164464            140           1035           8289
            0.002        18.1396      0.0163931            161           1017           8131
            0.002        15.8098      0.0161774             74           1004           8024
            0.002        16.8626      0.0162956            178           1026           8213
            0.002        19.0987      0.0171984            131           1084           8668
            0.002        17.3609      0.0160922             86            981           7853
            0.002        15.9344      0.0162103             75           1022           8170
            0.002        17.0157      0.0172055             86           1016           8121
            0.002        18.0302       0.017084            114           1091           8747
            0.002        17.7863      0.0177418            146           1081           8658
            0.002        16.6273      0.0157117            143            974           7793
            0.002        19.0943         0.0177            154           1061           8496
            0.002         16.057      0.0163937             72            982           7869
            0.002        16.8084      0.0153004            144            950           7589
           0.0022        19.5647      0.0181885            104           1144           9167
           0.0022        17.5356      0.0182708             79           1096           8770
           0.0022        18.3611      0.0190202            128           1177           9434
           0.0022        16.8895      0.0175371            153           1122           8979
           0.0022        20.4957      0.0184722            112           1164           9310
           0.0022        18.0491      0.0171738            152           1100           8793
           0.0022        20.9454       0.018621            134           1172           9385
           0.0022        21.0497      0.0188347            118           1167           9342
           0.0022        18.6939      0.0178849             94           1127           9014
           0.0022        18.8285      0.0182854            119           1096           8777
           0.0022        18.0666      0.0173477            104           1111           8882
           0.0022        19.1538       0.018375            174           1157           9261
           0.0022        19.6039       0.017668            143           1131           9046
           0.0022        20.4376      0.0175449            142           1122           8983
           0.0022        17.8895      0.0185205             87           1131           9038
           0.0022        16.8215       0.017873             79           1109           8865
           0.0022        19.5063      0.0189449            114           1116           8942
           0.0022        17.7816      0.0184004            102           1177           9421
           0.0022        20.3596      0.0186445            144           1193           9546
           0.0022        19.3321      0.0175813            245           1108           8861
           0.0024        20.6571      0.0188591            154           1187           9505
           0.0024        18.8349      0.0197937            107           1248           9976
           0.0024        23.9306      0.0206934            231           1326          10595
           0.0024        18.3397      0.0190079            117           1198           9580
           0.0024        21.5584      0.0196699            209           1259          10071
           0.0024        22.8192      0.0194637            251           1206           9654
           0.0024        19.5892      0.0196431            116           1217           9743
           0.0024        18.9019      0.0183016            311           1152           9224
           0.0024        20.1204      0.0198535            162           1271          10165
           0.0024        19.0559      0.0187383            129           1199           9594
           0.0024         19.653      0.0189883            123           1216           9722
           0.0024        18.9268      0.0196406            166           1257          10056
           0.0024        21.3553      0.0188036            135           1185           9477
           0.0024        21.4944       0.020129            276           1248           9984
           0.0024        21.2844      0.0191523            164           1227           9806
           0.0024        18.8211      0.0192163            110           1213           9685
           0.0024        21.6378         0.0195            154           1248           9984
           0.0024        20.1926      0.0192123            160           1210           9683
           0.0024        20.7389      0.0197004            132           1241           9929
           0.0024        20.8589      0.0193633            204           1240           9914
           0.0026        21.2286       0.021877            208           1378          11026
           0.0026        21.1732      0.0213313            137           1345          10751
           0.0026        24.5466      0.0204941            258           1310          10493
           0.0026        23.0849      0.0198906            225           1272          10184
           0.0026        21.8989      0.0205913            213           1296          10378
           0.0026        23.2764      0.0214861            131           1353          10829
           0.0026        25.6069      0.0216074            226           1384          11063
           0.0026        20.6516      0.0199306            139           1257          10045
           0.0026        22.9217      0.0209648            247           1341          10734
           0.0026        24.2442      0.0214336            182           1372          10974
           0.0026        20.4083       0.020332            172           1303          10410
           0.0026        24.1604       0.020621            447           1297          10393
           0.0026        21.8399      0.0209286            152           1318          10548
           0.0026        24.0091      0.0206699            249           1322          10583
           0.0026        26.6538      0.0207051            235           1326          10601
           0.0026        22.8878      0.0222843            199           1381          11053
           0.0026          23.33      0.0204643            275           1288          10314
           0.0026        25.1199      0.0212004            162           1335          10685
           0.0026         23.393      0.0212702            201           1318          10550
           0.0026         22.182      0.0212798            146           1341          10725
           0.0028        26.1602      0.0230496            320           1454          11617
           0.0028        21.5981      0.0219294             99           1361          10877
           0.0028        22.9101      0.0215352            173           1379          11026
           0.0028        25.7097      0.0224603            222           1416          11320
           0.0028        28.2201      0.0230176            221           1472          11785
           0.0028        23.9738      0.0230556            138           1451          11620
           0.0028          25.53      0.0228931            178           1419          11355
           0.0028        25.6745      0.0223175            239           1407          11248
           0.0028        24.5804       0.023041            229           1473          11797
           0.0028        28.0764      0.0230957            276           1479          11825
           0.0028        27.9372      0.0234043            220           1498          11983
           0.0028        30.0798      0.0242419            325           1504          12024
           0.0028        24.7856      0.0230363            162           1427          11426
           0.0028        25.6538      0.0219277            258           1404          11227
           0.0028        29.0258      0.0230059            336           1472          11779
           0.0028        25.3294      0.0224746            201           1439          11507
           0.0028        27.3821      0.0232202            202           1463          11703
           0.0028        28.3662        0.02325            220           1491          11904
           0.0028        27.4882      0.0234524            321           1479          11820
           0.0028        30.2229      0.0219492            311           1404          11238
            0.003        28.2497      0.0236543            342           1514          12111
            0.003        28.1676      0.0231934            206           1486          11875
            0.003        32.0369      0.0240913            393           1518          12142
            0.003        29.9016      0.0241113            234           1544          12345
            0.003        27.7203      0.0233594            171           1498          11960
            0.003        30.6239      0.0242222            251           1526          12208
            0.003         30.876      0.0226973            434           1452          11621
            0.003        31.1352      0.0249492            360           1598          12774
            0.003        29.7135      0.0241094            345           1543          12344
            0.003          27.49      0.0233887            278           1498          11975
            0.003        36.3477      0.0236607            687           1490          11925
            0.003         42.026      0.0252832            487           1618          12945
            0.003        29.9531      0.0243281            342           1557          12456
            0.003        28.7936      0.0242202            217           1526          12207
            0.003        29.4032      0.0249226            459           1570          12561
            0.003        34.8972      0.0241071            273           1518          12150
            0.003        39.3274       0.024625            509           1576          12608
            0.003        27.9437       0.023625            269           1511          12096
            0.003         29.489      0.0240859            220           1542          12332
            0.003        29.5114       0.023207            276           1486          11882
           0.0032        52.7733      0.0251563            585           1610          12880
           0.0032        39.2822      0.0251602            804           1609          12882
           0.0032         35.992      0.0253711            359           1625          12990
           0.0032        55.0278      0.0268095            488           1689          13512
           0.0032        35.4686      0.0253535            318           1624          12981
           0.0032        34.2213      0.0251367            357           1609          12870
           0.0032        30.1217      0.0254414            265           1627          13026
           0.0032        39.3841      0.0255391            349           1635          13076
           0.0032        29.3232      0.0247305            265           1584          12662
           0.0032        32.5975      0.0251567            409           1585          12679
           0.0032        39.1458         0.0255            465           1632          13056
           0.0032        46.9405       0.026293            855           1682          13462
           0.0032        33.8949      0.0257129            283           1646          13165
           0.0032        36.6235      0.0252246            514           1615          12915
           0.0032        33.8075      0.0265476            514           1673          13380
           0.0032         39.961      0.0252793            569           1617          12943
           0.0032        33.9602      0.0251445            450           1609          12874
           0.0032        35.4897      0.0259043            285           1658          13263
           0.0032        37.0792      0.0264238            457           1691          13529
           0.0032        28.5745      0.0248613            308           1591          12729
           0.0034        119.524      0.0275156           2619           1760          14088
           0.0034        66.1552      0.0275313           1149           1765          14096
           0.0034        43.5156      0.0255312            527           1633          13072
           0.0034        33.4938      0.0264316            317           1693          13533
           0.0034        91.8175      0.0281758           1358           1803          14426
           0.0034        55.6201      0.0270391            924           1732          13844
           0.0034        54.4463        0.02675            974           1712          13696
           0.0034        62.8228      0.0268086            665           1716          13726
           0.0034        67.4188      0.0282305            897           1805          14454
           0.0034        43.1392      0.0262617            519           1681          13446
           0.0034        77.6248      0.0281706           1064           1775          14198
           0.0034        38.0923      0.0262383            341           1680          13434
           0.0034        40.7601      0.0271367            455           1738          13894
           0.0034        66.1937      0.0279316            826           1786          14301
           0.0034        30.5383      0.0269121            206           1722          13779
           0.0034        47.2954      0.0271984            632           1713          13708
           0.0034        40.8932      0.0275098            306           1761          14085
           0.0034        34.8011      0.0263333            283           1659          13272
           0.0034        40.6983      0.0260605            387           1667          13343
           0.0034        61.1145      0.0283535            729           1816          14517
           0.0036        74.1937      0.0283008           1055           1812          14490
           0.0036        83.0453      0.0286055           1106           1832          14646
           0.0036        138.281      0.0286289           2330           1832          14658
           0.0036        74.4318      0.0280605            706           1795          14367
           0.0036        56.4682      0.0280137            819           1792          14343
           0.0036        146.907      0.0291152           1434           1866          14907
           0.0036        250.643       0.029623           3055           1895          15167
           0.0036        70.7846      0.0280625            694           1797          14368
           0.0036        98.7918      0.0283066           1793           1811          14493
           0.0036         67.913      0.0292361            648           1840          14735
           0.0036        68.4247      0.0290059            942           1858          14851
           0.0036        150.044      0.0292715           2812           1873          14987
           0.0036        132.022      0.0286465           1417           1834          14667
           0.0036        69.7636      0.0293184           1518           1878          15011
           0.0036         99.136      0.0291895           1321           1868          14945
           0.0036        94.3027      0.0288496           1553           1847          14771
           0.0036        155.721       0.029998           2360           1890          15119
           0.0036        94.8307      0.0296211           2252           1896          15166
           0.0036        53.6757      0.0289199            716           1850          14807
           0.0036        101.342      0.0297383           1728           1904          15226
];

rows = size(data, 1);
cols = size(data, 2);

data_delay = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+1);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_delay = [data_delay; data(ifirst, 1:cols-5), avg ci];
end

figure(1);
hold on;
plot(data_delay(:,1), data_delay(:,2), symbol);

data_throughput = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+2);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_throughput = [data_throughput; data(ifirst, 1:cols-5), avg ci];
end

figure(2);
hold on;
plot(data_throughput(:,1), data_throughput(:,2), symbol);

data_maxdelay = [];
for i = 1:rows/20,
   ifirst = (i - 1) * 20 + 1;
   ilast  = ifirst + 20 - 1;
   tmp = data(ifirst:ilast, cols-5+3);
   avg = mean(tmp);
   [h sig ci] = ttest(tmp, 0.1);
   ci = (ci(2)-ci(1))/2;
   data_maxdelay = [data_maxdelay; data(ifirst, 1:cols-5), avg ci];
end

figure(3);
hold on;
plot(data_maxdelay(:,1), data_maxdelay(:,2), symbol);


%-------- Saturation Analysis -----------
slope=[];
for i=2:size(data_throughput,1),
    slope(i-1) = (data_throughput(i,2)-data_throughput(i-1,2))/(data_throughput(i,1)-data_throughput(i-1,1));
end

for i=2:size(slope,2),
    if slope(i) < (0.95*mean(slope(1:i)))
        max_pir = data_throughput(i, 1);
        max_throughput = data_throughput(i, 2);
        min_delay = data_delay(i, 2);
        break;
    end
end
